package com.example.shop_2208

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.example.shop_2208.databinding.ActivityWelcome2Binding
import com.example.shop_2208.entity.UserEntity
import com.example.shop_2208.login.LoginActivity
import com.example.shop_2208.mvvm.BaseViewActivity
import com.example.shop_2208.net.Const
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class WelcomeActivity2 : BaseViewActivity<ActivityWelcome2Binding>() {
    override fun initData() {

    }

    override fun initView() {
        //
        binding.user = UserEntity("八维",false,"",1,"",
            "http://10.161.9.80:8080/res/icon/5cd9f1846cec48ab875c21776de188b3.jpeg",1,"","111111","","","",1,"111111")
        lifecycleScope.launch {
            for(i in 5 downTo 0){
                binding.time = i
                if(i==0){
                    /*if(SPUtils.getInstance().getString(Const.SP_TOKEN).isNotEmpty()){
                       //startActivity(Intent(this@WelcomeActivity2,MainActivity::class.java))
                        //build：查找路径  navigation：控制页面进行跳转
                        ARouter.getInstance().build("/app/main").navigation()
                        ARouter.getInstance().build("/app/login").navigation()
                    }else{
                        //startActivity(Intent(this@WelcomeActivity2,LoginActivity::class.java))
                        ARouter.getInstance().build("/app/login").navigation()
                    }*/
                    //应用了ARouter拦截器--直接跳转到主页面，当未登录时，会自动跳转到登录界面
                    ARouter.getInstance().build("/app/main").navigation()
                }
                delay(1000)//延迟1秒，达到倒计时的效果
            }
        }
    }

    override fun getLayout(): Int  = R.layout.activity_welcome2

}